package com.chengh.nami.web.controller.system.log;

import com.chengh.nami.common.request.PageQuery;
import com.chengh.nami.common.response.PageData;
import com.chengh.nami.common.response.R;
import com.chengh.nami.system.domain.dto.LogininforDto;
import com.chengh.nami.system.pojo.SysLogininfor;
import com.chengh.nami.system.service.ISysLogininforService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


/**
 * 登录日志控制器
 *
 * @author chengh
 */
@Slf4j
@RequiredArgsConstructor
@RestController()
@RequestMapping("/system/log/logininfor")
@Tag(name = "LogininforController", description = "登录日志管理")
public class LogininforController {

    private final ISysLogininforService logininforService;

    /**
     * 获取登录日志列表
     *
     * @return 登录日志信息
     */
    @GetMapping("/list")
    @Operation(summary = "获取所有的用户登录日志", description = "")
    public R<PageData<SysLogininfor>> list(LogininforDto logininforDto, PageQuery pageQuery) {
        PageData<SysLogininfor> logininforPageData = logininforService.getList(logininforDto, pageQuery);
        return R.ok(logininforPageData);
    }

    /**
     * 清空所有的日志
     *
     * @return 返回结果
     */
    @DeleteMapping
    @Operation(summary = "清空所有的日志", description = "")
    public R<Void> cleanLogininfor() {
        logininforService.cleanLogininfor();
        return R.ok();
    }

    @PostMapping("/export")
    @Operation(summary = "导出登录日志信息", description = "")
    public void export(HttpServletResponse response, LogininforDto logininforDto, PageQuery pageQuery) {
        logininforService.exportLogininforExcle(response, logininforDto, pageQuery);
    }

}
